package edu.tongji.jiaowu.dao.jdbc;

import java.util.List;

import edu.tongji.jiaowu.dao.GradeMajorDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class GradeMajorDaoJdbc extends BaseDaoJdbc implements GradeMajorDao {
	String tableName = "T_GRADE_MAJOR";

	String beanName = "gradeMajor";

	public CommonBean createGradeMajor() {
		CommonBean gradeMajors = this.createBean(tableName, beanName);
		return gradeMajors;
	}

	/*
	 * public CommonBean findGradeMajors(String refid) { CommonBean
	 * gradeMajors=this.createGradeMajor(); String sql="select * from
	 * T_GRADE_MAJOR where refid=?"; List
	 * data=this.getCommonDao().select(sql,new String[]{refid});
	 * gradeMajors.addData(data); return gradeMajors; }
	 */
	public CommonBean findGradeMajorById(String id) {
		CommonBean gradeMajors = this.createGradeMajor();
		String sql = "select * from T_GRADE_MAJOR where id=?";
		List data = this.getCommonDao().select(sql, new String[] { id });
		gradeMajors.addData(data);
		return gradeMajors;
	}

	public CommonBean findAllGradeMajors() {
		CommonBean gradeMajors = this.createGradeMajor();
		String sql = "select * from T_GRADE_MAJOR  order by major_no";
		List data = this.getCommonDao().select(sql, new String[] {});
		gradeMajors.addData(data);
		return gradeMajors;
	}

	public void insertGradeMajor(CommonBean gradeMajorBean) {
		List data = gradeMajorBean.getData();
		Row row = this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row, data, this.getIdGenerator());
	}

	public CommonBean findGraduateMajors(String year) {
		CommonBean gradeMajors = this.createGradeMajor();
		String sql = "select * from T_GRADE_MAJOR where (grade+num_year)=? order by major_no";
		List data = this.getCommonDao().select(sql, new String[] { year });
		gradeMajors.addData(data);
		return gradeMajors;
	}

	public CommonBean findDirectionMajors() {
		CommonBean gradeMajors = this.createGradeMajor();
		String sql = "select * from T_GRADE_MAJOR t where exists(select * from T_MAJOR_DIRECTION  where refid=t.id) "+
		            " and grade+num_year>=convert(char(4),getdate(),120) order by major_no";
		List data = this.getCommonDao().select(sql, new String[] {});
		gradeMajors.addData(data);
		return gradeMajors;	
	}

	public CommonBean findSchoolClassMajors() {
		CommonBean gradeMajors = this.createGradeMajor();
		String sql = "select * from T_GRADE_MAJOR t where exists(select * from T_MAJOR_CLASS  where refid=t.id) "+
		            " and grade+num_year>=convert(char(4),getdate(),120) order by major_no";
		List data = this.getCommonDao().select(sql, new String[] {});
		gradeMajors.addData(data);
		return gradeMajors;	
	}
}
